<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    request.setCharacterEncoding("UTF-8");
    String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
%>
<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>用户管理</title>
    <jsp:include page="../../head.jsp"/>
    <style type="text/css">
        .td_right {
            text-align: right;
        }
    </style>
    <script>
        var contentHtml = "";
        var editor;
        $(document).ready(function () {
            var companyType = "${companyType}";
            if (companyType == "CL" || companyType == "CC") {
                $("#userType").hide();
                $("#type").val("2");
                if ($("#userId").val() != "") {
                    $("#account").attr("disabled", true);
                }
            }

            //初始化表单验证引擎
            $("#userForm").validationEngine("attach", {
                //消息位置
                promptPosition: "bottomRight",
                scroll: false
            });
            //初始化ajaxForm参数
            var options = {
                //提交方式
                type: "POST",
                //提交数据格式
                dataType: "json",
                //在提交之前做的操作
                beforeSubmit: function () {
                    return $("#userForm").validationEngine("validate");
                },
                //成功后做的操作
                success: function (responseText, statusText, xhr, $form) {
                    alert(responseText.msg);
                    if (responseText.result) {
                        location.href = "company-mainUser?id=" + $("#deptId").val();
                    }
                }
            };
            $('#userForm').ajaxForm(options);
        });
        function submitTheForm() {
            var userid = $('[name=id]').val();
            if (userid == "" || userid == null) {
                var account = $("#account").val();
                $.ajax({
                           url: "company-checkUserExist",
                           type: "POST",
                           dataType: "json",
                           data: "account=" + account,
                           success: function (data) {
                               if ($.parseJSON(data.msg) != null) {
                                   if ($.parseJSON(data.msg).state == "1") {
                                       alert($.parseJSON(data.msg).msg);
                                       return;
                                   }
                               } else {
                                   $("#userForm").submit();
                               }
                           }
                       });
            } else {
                $("#userForm").submit();
            }

        }

    </script>
</head>
<body class="base_font_size">
<%=htmlData%>
<form name="example" id="userForm" method="post" action="company-saveOrUpdateUser">
    <div class="ui-widget">
        <table class="ui-widget-content" style="width: 100%;">
            <tr>
                <td class="td_right td_right_individualStyle">用户名</td>
                <td><input class="validate[required] input_individualStyle" type="text"
                           id="user_name" name="name"
                           value="${users.name}"/>*
                </td>
                <td class="td_right td_right_individualStyle">用户密码</td>
                <td><input class="validate[required] input_individualStyle" type="password"
                           name="pwd"
                           value=""/>*
                </td>
            </tr>
            <tr>
                <td class="td_right td_right_individualStyle">用户账号</td>
                <td><input class="validate[required] input_individualStyle" id="account" type="text"
                           name="account"
                           value="${users.account}"/>*
                </td>
                <td class="td_right td_right_individualStyle">手机号码</td>
                <td><input class="input_individualStyle" type="text" name="mobile"
                           value="${users.mobile}"/></td>
            </tr>
            <tr>
                <td class="td_right td_right_individualStyle">固定电话</td>
                <td><input class=" input_individualStyle" type="text" name="telphone"
                           value="${users.telphone }"/>
                </td>
                <td class="td_right td_right_individualStyle">邮箱地址</td>
                <td><input class="input_individualStyle" type="text" name="email"
                           value="${users.email}"/>
                </td>
            </tr>
            <tr id="userType">
                <td class="td_right td_right_individualStyle">用户类型</td>
                <!-- 					<td colspan="3"> -->
                <td>
                    <select style="margin: 5px 5px 0 0;" id="type" name="type">
                        <c:choose>
                            <c:when test="${users.type eq 0}">
                                <option value="0" selected="selected">系统管理员</option>
                                <option value="1">公司管理员</option>
                                <option value="2">公司普通职员</option>
                            </c:when>
                            <c:when test="${users.type eq 1}">
                                <option value="0">系统管理员</option>
                                <option value="1" selected="selected">公司管理员</option>
                                <option value="2">公司普通职员</option>
                            </c:when>
                            <c:when test="${users.type eq 2}">
                                <option value="0">系统管理员</option>
                                <option value="1">公司管理员</option>
                                <option value="2" selected="selected">公司普通职员</option>
                            </c:when>
                            <c:otherwise>
                                <option value="0">系统管理员</option>
                                <option value="1">公司管理员</option>
                                <option value="2">公司普通职员</option>
                            </c:otherwise>
                        </c:choose>
                    </select>
                </td>

            </tr>
            <!-- 				<tr> -->
            <!-- 					<td class="td_right td_right_individualStyle">手机验证</td> -->
            <!-- 					<td colspan="3"></td> -->
            <!-- 				</tr> -->
            <tr>
                <td colspan="4" align="center" class="bts">
                    <input class="button_individualStyle" type="button" onclick="submitTheForm()"
                           name="btn"
                           value="应用存盘"/>
                    <input class="button_individualStyle" type="button"
                           onclick="javascript:history.back();" name="btn"
                           value="返回"/>
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" name="deptId" id="deptId" value="${deptId}"/>
    <input type="hidden" id="id" name="id" value="${users.id}"/>
    <input type="hidden" name="isabled" value="${users.isabled}"/>
    <input type="hidden" name="state" value="${users.state}"/>
</form>
</body>
</html>
